import {WeaLocaleProvider} from "ecCom";
const getLabel = WeaLocaleProvider.getLabel;

export const menuData = store => [{
    command: store['edc.excelView.tableInsertCombineRow'],
    text: getLabel('503000','插入合并行'),
    name: "edc.excelView.tableInsertCombineRow",
    workArea: "viewporttable",
}, {
    command: store['edc.excelView.tableInsertTopRow'],
    text: getLabel('502989','在上方插入表行'),
    name: "edc.excelView.tableInsertTopRow",
    workArea: "viewporttable",
}, {
    command: store['edc.excelView.tableInsertBottomRow'],
    text: getLabel('502990','在下方插入表行'),
    name: "edc.excelView.tableInsertBottomRow",
    workArea: "viewporttable",
}, {
    command: store['edc.excelView.tableDeleteRow'],
    text: getLabel('502992','删除表行'),
    name: "edc.excelView.tableDeleteRow",
    workArea: "viewporttable",
}]
export const setRightMenu = (store, isTable, isFirstDataRow, table, cellType, rowControl) => {
    const datas = menuData(store);
    if (isTable) {
        const bindingPath = table.bindingPath();
        if(!bindingPath) {
            return;
        }
        const paths = bindingPath.split('.');
        const sheetName = paths[0];
        let isAddRow = 1;
        let isDeleteRow = 1;
        rowControl[sheetName].forEach(item => {
            if(bindingPath == item.bindingPath){
                isAddRow = item.isAddRow;
                isDeleteRow = item.isDeleteRow;
                return;
            }
        });
        if(0 == isAddRow){
            delete datas[0];
            delete datas[1];
            delete datas[2];
            // datas.splice(0,3);
        } 
        if(0 == isDeleteRow){
            delete datas[3];
            // datas.splice(3,1);
        }

        if(!cellType){
            delete datas[0];
            delete datas[1];
            delete datas[3];
        }

        if (isFirstDataRow) {
            store.workbook.contextMenu.menuData = datas.filter(d => {
                if (d.subMenu) {
                    d.subMenu = d.subMenu.filter(f => {
                        return /table/i.test(f.workArea) && !(/nofirstdatarow/i.test(f.workArea))
                    });
                }
                return /table/i.test(d.workArea) && !(/nofirstdatarow/i.test(d.workArea))
            });
        } else {
            store.workbook.contextMenu.menuData = datas.filter(d => /table/i.test(d.workArea))
        }
    } else {
        store.workbook.contextMenu.menuData = datas.filter(d => d.workArea !== 'viewporttable');
    }
}